/**
 * @ClassName: BuickCareContentFragment
 * @Description: 别克关怀
 * @author Mengting Lu
 * @date 2015年7月31日 下午3:53:47
 */
package com.shanghaionstar.user;

import android.app.Activity;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.TextView;

import com.onstar.cn.common.exception.OnStarException;
import com.onstar.cn.common.log.LogManager;
import com.onstar.cn.common.util.DeviceUtil;
import com.onstar.cn.framework.annotation.FindViewById;
import com.onstar.cn.framework.annotation.OnClick;
import com.onstar.cn.framework.mvp.base.core.BaseActivity;
import com.onstar.cn.framework.mvp.base.core.BaseFragment;
import com.onstar.cn.mag.enumtype.CategoryType;
import com.onstar.cn.more.response.GetContentListResponseType;
import com.onstar.cn.weight.ProgressLayout;
import com.shanghaionstar.R;
import com.shanghaionstar.enumtype.FunctionNameFindId;
import com.shanghaionstar.enumtype.LanguageType;
import com.shanghaionstar.user.adapter.BuickContentListAdapter;
import com.shanghaionstar.user.iview.IBuickCareView;
import com.shanghaionstar.user.presenter.BuickCarePresenter;
import com.shanghaionstar.utils.AlertDialogUtil;
import com.shanghaionstar.weight.TopLayout;

/**
 * @author Mengting Lu
 * @ClassName: BuickCareContentFragment
 * @Description: 别克关怀
 * @date 2015年7月31日 下午3:53:47
 */
public class BuickCareContentFragment extends BaseFragment implements IBuickCareView {
    private BaseActivity parent;
    @FindViewById
    private RadioButton assistant_buick_bestservice_id;
    @FindViewById
    private RadioButton assistant_buick_activityinfo_id;
    @FindViewById
    private RadioButton assistant_buick_maintaintips_id;
    @FindViewById
    private TopLayout top_layout;
    @FindViewById(value = R.id.assistant_content_list_id)
    private ListView title_list;
    @FindViewById
    private ProgressLayout content_list_progress;
    @FindViewById(value = R.id.assistant_buick_hdxx_null_id)
    private TextView hdxxNullTextView;
    @FindViewById(value = R.id.assistant_buick_hdxx_null_id_2)
    private TextView hdxxNullTextView2;

    private BuickCarePresenter presenter;

    private LogManager logger = LogManager.getInstance();

    @Override
    public int getLayoutId() {
        return R.layout.buick_care_list;
    }


    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        if (isFirstLoad()) {
            parent = (BaseActivity) getActivity();
            presenter = new BuickCarePresenter(parent.getScheduler());
            presenter.setView(this);
            presenter.initData();
        }
        top_layout.setTopTitle(R.string.assistant_buickCare);
        btnBackClick(top_layout);
    }


    // F5609 BuikQualityService REPORT 点击别克关怀页的精品服务 lu rengui
    // F5610 BuikServiceInformation REPORT 点击别克关怀页的活动信息 lu rengui
    // F5611 BuikYangCheGuanHuai REPORT 点击别克关怀页的养车关怀 lu rengui

    @OnClick({R.id.assistant_buick_bestservice_id, R.id.assistant_buick_activityinfo_id,
            R.id.assistant_buick_maintaintips_id})
    public void OnClick(View view) {
        if (view.getId() == R.id.assistant_buick_bestservice_id) {
            presenter.onTitleClick(FunctionNameFindId.BuikQualityService, CategoryType.BUICK_CARE_JPFW);
        } else if (view.getId() == R.id.assistant_buick_activityinfo_id) {
            presenter.onTitleClick(FunctionNameFindId.BuikServiceInformation, CategoryType.BUICK_CARE_HDXX);
        } else if (view.getId() == R.id.assistant_buick_maintaintips_id) {
            presenter.onTitleClick(FunctionNameFindId.BuikYangCheGuanHuai, CategoryType.BUICK_CARE_YCTS);
        }
    }

    public BuickCareContentFragment() {

    }


    /**
     * (non-Javadoc)
     * <p>
     * Title: onDestroy
     * </p>
     * <p>
     * Description:
     * </p>
     *
     * @see android.support.v4.app.Fragment#onDestroy()
     */
    @Override
    public void onDestroy() {
        super.onDestroy();
        top_layout = null;
    }

    @Override
    public void setLoading(boolean isLoading) {
        content_list_progress.setVisibility(isLoading ? View.VISIBLE : View.GONE);
    }

    @Override
    public void onResponseError(OnStarException e) {
        AlertDialogUtil.showDialogByOnstarException(parent, e);
    }

    @Override
    public void onReponseSuccess(GetContentListResponseType object) {

    }

    @Override
    public Activity onActivity() {
        return getActivity();
    }

    @Override
    public void initContentListPage(GetContentListResponseType contentHeaderType) {
        if (contentHeaderType.getContentHeaderList() != null && contentHeaderType.getContentHeaderList().size() > 0) {
            hdxxNullTextView.setVisibility(View.GONE);
            hdxxNullTextView2.setVisibility(View.GONE);
            View footerView = LayoutInflater.from(parent).inflate(R.layout.user_guide_footer, null);
            if (title_list.getFooterViewsCount() == 0)
                title_list.addFooterView(footerView);
            title_list.setAdapter(new BuickContentListAdapter(contentHeaderType.getContentHeaderList(), getActivity()));
            title_list.setVisibility(View.VISIBLE);
        } else {
            hdxxNullTextView.setVisibility(View.VISIBLE);
            if (LanguageType.fromValue(DeviceUtil.getLanguage()).getValue().equals("CHINESE")) {
                hdxxNullTextView2.setVisibility(View.VISIBLE);
            }
            title_list.setVisibility(View.GONE);
        }
        if (LanguageType.fromValue(DeviceUtil.getLanguage()).getValue().equals("ENGLISH")) {
            assistant_buick_bestservice_id.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11);
            assistant_buick_activityinfo_id.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11);
            assistant_buick_maintaintips_id.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11);
        }

        title_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
                presenter.onItemClick(position);
            }
        });

    }
}
